﻿using DevExpress.Utils.MVVM;
using DevExpress.Utils.MVVM.UI;
using DevExpress.Utils.Svg;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DotNetExtensions.AspNet.DevExpress.Behaviors;
using DotNetExtensions.AspNet.DevExpress.Services;
using Habi.Solver.Models;
using Habi.Solver.Services;
using Habi.Solver.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Habi.Solver.Views
{
    [ViewType(MainViewModel.DashboardView)]
    public partial class DashboardView : XtraUserControl
    {
        private IGridViewService gridViewService;
        public DashboardView()
        {
            InitializeComponent();
            gridViewService = new GridViewService();
            mvvmContext.ViewModelType = typeof(DashboardViewModel);

            mvvmContext.RegisterService(new DialogMessageBoxService(this));
            mvvmContext.RegisterService(new ClipboardService());
            mvvmContext.AttachBehavior<ControlCBehavior>(gridView);

            if (!mvvmContext.IsDesignMode) InitializeChart();
        }

        private void InitializeChart()
        {
            var fluent = mvvmContext.OfType<DashboardViewModel>();
            fluent.WithEvent(this, "Load").EventToCommand(x => x.Load());

            fluent.SetBinding(gridControl, g => g.DataSource, x => x.Apps);
          
            fluent.WithEvent<GridView, FocusedRowObjectChangedEventArgs>(gridView, "FocusedRowObjectChanged")
               .SetBinding(x => x.ActivedAppModel,
                   args => args.Row as AppModel,
                   (gView, entity) => gView.FocusedRowHandle = gView.FindRow(entity));
            
            gridViewService.Indicator<AppModel>(gridControl);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }
    }
}
